#include <algorithm>
#include "pub_defs.h"
void gameoflife_baseline(uint8_t* arr, const int m, const int n) {
    uint8_t* tmp_arrs[2];
    tmp_arrs[0] = new uint8_t[(m+2)*(n+2)];
    tmp_arrs[1] = new uint8_t[(m+2)*(n+2)];
    std::copy(arr, arr+(m+2)*(n+2), tmp_arrs[0]);
    for (int gen=0;gen<GEN;gen++){
        int tg = gen%2;
        int ng = (gen+1)%2;
        for (int i = 1; i < m+1; i++) {
            for (int j = 1; j < n+1; j++) {
                int neightbours = 
                    VA(tmp_arrs[tg], i-1, j-1, n)
                    +VA(tmp_arrs[tg], i-1, j, n)
                    +VA(tmp_arrs[tg], i-1, j+1, n)
                    +VA(tmp_arrs[tg], i, j-1, n)
                    +VA(tmp_arrs[tg], i, j+1, n)
                    +VA(tmp_arrs[tg], i+1, j-1, n)
                    +VA(tmp_arrs[tg], i+1, j, n)
                    +VA(tmp_arrs[tg], i+1, j+1, n);
                
                switch (neightbours) {
                    case 0:
                        VA(tmp_arrs[ng], i, j, n) = 0;
                        break;
                    case 1:
                        VA(tmp_arrs[ng], i, j, n) = 0;
                        break;
                    case 2:
                        VA(tmp_arrs[ng], i, j, n) = VA(tmp_arrs[tg], i, j, n);
                        break;
                    case 3:
                        VA(tmp_arrs[ng], i, j, n) = 1;
                        break;
                    default:
                        VA(tmp_arrs[ng], i, j, n) = 0;
                }
            }    
        }
    }
    int endindex = (GEN)%2;
    std::copy(tmp_arrs[endindex], tmp_arrs[endindex]+(m+2)*(n+2), arr);
}